<?php
function set_baidu(){
    include './config.php';
    $sql = "SELECT Id FROM book WHERE flg=1 ORDER BY id DESC";
    $urls = array();
    $stmt = $conn->query($sql);
    $stmt->execute();
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
    $result = $stmt->fetchAll();
    for($i = 0; $i < count($result); $i++){
        $t = '你的网址/view/item/'.$result[$i]['Id'].'.html';
        array_push($urls, $t);
    };
    array_push($urls, '你的网址/view/item/index.html');
    
    $api = 'http://data.zz.baidu.com/urls?site=你的网址&token=你的token';
    $ch = curl_init();
    $options =  array(
        CURLOPT_URL => $api,
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POSTFIELDS => implode("\n", $urls),
        CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
    );
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    updata_bai($urls);
    echo $result;
};

set_baidu();


function updata_bai($data){
    $urls = $data;
    $api = 'http://data.zz.baidu.com/update?site=你的网址&token=你的token';
    $ch = curl_init();
    $options =  array(
        CURLOPT_URL => $api,
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POSTFIELDS => implode("\n", $urls),
        CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
    );
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    echo $result;
};